﻿module.exports = {
    run: run,
    addMessages: addMessages
}

function run(context, timerInfo) {
    var timeStamp = new Date().toISOString();
    context.log('Node.js timer trigger function ran!', timeStamp);

    context.log('PastDue:', timerInfo.isPastDue);
    context.log('Last:', timerInfo.last);
    context.log('Next:', timerInfo.next);

    addMessages(context);

    context.done();
}

function addMessages(context) {
    context.bindings.messages = [];

    for (i = 0; i < 3; i++) {
        context.bindings.messages.push({
            id: Math.floor(Math.random() * 10000) + 1,
            notes: "Generated by Timer function"
        });
    }
}